package net.zubara.esni.core.client;

import java.io.NotSerializableException;
import java.util.Map;

import net.zubara.esni.core.pojo.StatusGetResponse;

import org.eclipse.ecf.remoteservice.IRemoteCall;
import org.eclipse.ecf.remoteservice.client.IRemoteCallable;
import org.eclipse.ecf.remoteservice.client.IRemoteResponseDeserializer;

import com.thoughtworks.xstream.XStream;

public class XMLRemoteResponseDeserializer implements IRemoteResponseDeserializer {

	@Override
	public Object deserializeResponse(String endpoint, IRemoteCall call, IRemoteCallable callable, Map responseHeaders, String responseBody)
			throws NotSerializableException {
		Object result = null;
		try {
			System.out.println(responseBody);
			XStream xs = initXStream();
			result = xs.fromXML(responseBody);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	private XStream initXStream() {
		XStream xstream = new XStream();
		xstream.processAnnotations(StatusGetResponse.class);
		return xstream;
	}

}
